﻿var g_iCount = 30;

function showTime()
{
    alert('Show Time');
}

function startTime() {
    var Compare = document.getElementById('ctl00_txtTimeToCompare');
    var TimeResult = document.getElementById('txtTimeResult');

    var myArray = Compare.innerHTML.split(",");

    var timetoCompare = new Date(myArray[0], myArray[1], myArray[2], myArray[3], myArray[4], myArray[5]);

    var today = new Date();
    var h = today.getHours();
    var m = today.getMinutes();
    var s = today.getSeconds();

    // add a zero in front of numbers<10
    m = checkTime(m);
    s = checkTime(s);

    var tResult = new Date(today - timetoCompare);

    var hCompare = tResult.getHours();
    var mCompare = tResult.getMinutes();
    var sCompare = tResult.getSeconds();
    mCompare = checkTime(mCompare);
    sCompare = checkTime(sCompare);

    TimeResult.innerHTML = 'Tempo para próxima atualização: ' + checkTime((5 - mCompare - 1)) + ":" + checkTime((60 - sCompare - 1));

    if (TimeResult.innerHTML.indexOf('-') != -1) {// || TimeResult.innerHTML.indexOf('Delay')) {
        g_iCount = g_iCount - 1;
        TimeResult.innerHTML = 'Delay de ' + mCompare + ':' + sCompare + ' - Próxima tentativa em 00:' + checkTime(g_iCount) + 's';
        t = setTimeout('startTime()', 1000);

        if (TimeResult.innerHTML.indexOf('00:00') != -1) {
            window.navigate(location.href);
        }

    }
    else {
        t = setTimeout('startTime()', 1000);
    }
}

function checkTime(i) {
    if (i < 10) {
        i = "0" + i;
    }
    return i;
}

function switchViews(obj,row)
        {
            var div = document.getElementById(obj);
            var img = document.getElementById('img' + obj);
            
            if (div.style.display=="none")
                {
                    div.style.display = "inline";
                    if (row=='alt')
                       {
                           img.src = "../img/minus.gif";
                       }
                   else
                       {
                           img.src = "../img/minus.gif";
                       }                   
               }
           else
               {
                   div.style.display = "none";
                   if (row=='alt')
                       {
                           img.src = "../img/more.gif";
                       }
                   else
                       {
                           img.src = "../img/more.gif";
                       }                   
               }
       }